package wx;


import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

public class Client {
    @Test
    public void testClient(){
        String result = HttpUtil.get("https://www.baidu.com");
        System.out.println(result);
    }
    @Test
    public void weatherTest(){
        String url = "https://freecityid.market.alicloudapi.com/whapi/json/alicityweather/briefforecast3days";
        String appcode = "b42704c1c6504bf58103f0b7064f0269";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, Object> bodys = new HashMap<>();
        bodys.put("cityId", "651");
        HttpResponse response = HttpUtil.createRequest(Method.POST, url).addHeaders(headers).form(bodys).execute();
        System.out.println(response);
    }

    @Test
    public void threadTest(){
        for (Thread.State value : Thread.State.values()) {
            System.out.println(value);
        }
    }
}
